/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.dwusoft.task.api  
 */
package com.dwusoft.sendmsg.service.template;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * description:  定时任务启动控制类
 * @author Hou Dayu 创建时间：2015-1-14  
 * @Copyright(c)2014:北京东吴软件技术有限公司
 */
public class ScheduledExecutor {

	private static ScheduledExecutor instance;
	private ScheduledExecutorService scheduExec;

	private ScheduledExecutor() {
	}

	/**
	 * description:  创建单实例方法
	 * @return   
	 * @author Hou Dayu  
	 * @update 2015-1-14
	 */
	public static ScheduledExecutor newInstance() {
		return instance;
	}

	/**
	 * description:    开启全部任务 
	 */
	private void start() {
//		long timeLong = 5 * 60 * 1000;
		long timeLong = 30000;
		scheduExec.scheduleAtFixedRate(new SendmsgTask(), timeLong, timeLong, TimeUnit.MILLISECONDS);
	}

	/**
	 * description: 初始化方法
	 * @author Hou Dayu  
	 * @update 2015-1-14
	 */
	public void init() {
		instance = this;
		scheduExec = Executors.newScheduledThreadPool(1);
		start();
	}

	/**
	 * description:  销毁方法
	 * @author Hou Dayu  
	 * @update 2015-1-14
	 */
	public void destroy() {
		scheduExec.shutdown();
		scheduExec = null;
		instance = null;
	}

}
